<!-- 发起演练 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: #777777;font-size: 48rpx;" slot="content">发起演练</block>
		</cu-custom>

		<view class="cu-form-group margin-top">
			<view class="title">区域名称</view>
			<picker @change="bindPickerChange($event,qyList)" :value="index" :range="qyList" :range-key="'name'">
				<view class="uni-input">
					{{index>-1?qyList[index].name:'请选择区域'}}
				</view>
			</picker>
		</view>


		<view class="cu-form-group margin-top">
			<view class="title">详细地址</view>
			<input v-model="address" placeholder="请输入详细地址" name="address"></input>
		</view>

		<view class="padding flex flex-direction">
			<button class="cu-btn margin-tb-sm lg my-btn" @click="submit">发送通知</button>

		</view>

	</view>
</template>

<script>
	export default {
		onLoad() {
			let _this = this
			// 请求数据
			let app = getApp()
			app.globalData.request({
				url: 'wx/fireInfo/getRegionList',
			}).then(function(res) {
				let list = res.data.data
				_this.qyList = list

			}).catch(function(e) {})
		},
		data() {
			return {
				index: -1,

				// picker下拉数据源
				qyList: '',
				pickerData: '',
				address: '',
			}
		},
		methods: {
			bindPickerChange: function(e, storage) {
				this.index = e.target.value
				this.pickerData = storage[this.index] // 这里就是选中的对象
				console.log("选中：" + this.pickerData.ucId + "--" + this.pickerData.name)
			},

			submit() {
				let params = {
					"location": this.address,
					"regionId": this.pickerData.ucId,
					"regionName": this.pickerData.name
				}
				let app = getApp()
				app.globalData.request({
					url: '/wx/fireInfo/drillNotice',
					data: {
						...params
					}
				}).then(function(res) {
					let data = res.data.code
					if (data == 0) {
						uni.showToast({
							title: "发起演练成功"
						})
						uni.navigateBack({
							delta: 2
						});
					} else {
						uni.showToast({
							title: res.data.msg
						})
					}

				}).catch(function(e) {})
			},
		}

	}
</script>

<style scoped>
	.my-btn {
		height: 94rpx;
		margin-top: 80px;
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
		border-radius: 24px;
		ont-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
	}
</style>
